package example.documentbased.editorModule.views.components
{
	import example.documentbased.editorModule.common.EditorViewHelper;
	import example.documentbased.mainModule.models.vo.DocumentVO;
	
	import spark.components.ButtonBarButton;
	import spark.primitives.Rect;
	
	public class EditorButtonBarButton extends ButtonBarButton
	{
		[SkinPart(required="false")]
		public var editedBg:Rect;
		
		override public function set data(value:Object):void
		{
			super.data = value;
			
			updateEditedBackground();
		}
		
		override protected function partAdded(partName:String, instance:Object):void {
			
			super.partAdded(partName, instance);
			
			if (data && instance == editedBg)
			{
				updateEditedBackground();
			}
		}
		
		private function updateEditedBackground():void
		{
			if (editedBg && data)
			{
				editedBg.visible = EditorViewHelper.getIsEditedDocument(data as DocumentVO);
			}
		}
	}
}